
/**
 * 权限服务
 */
interface IauthorityService {
    getList():any;
}

class authorityService implements IauthorityService {
    constructor(private http: ng.IHttpService,private $q:ng.IQService, private route: routeService,private authorizationService:authorizationService,private authorizationTypeService:IAuthorizationTypeService) {
    }
    
    getList():any{
        var deferred = this.$q.defer();
        var AuthorizationList = [];
        var AuthorizationTypeList = [];
        var authorList = [];
        this.authorizationTypeService.getList("",0,-1).then(res=>{
            AuthorizationTypeList = res.data.data;

            //获取    
            this.authorizationService.getList("","",0,-1).then(res=>{
                AuthorizationList = res.data.data;

                AuthorizationTypeList.forEach((item,index)=>{
                    var typeTag = item.name;
                    var newAuth = [];
                    AuthorizationList.forEach((items,indxes)=>{
                        if(typeTag === items.category){
                            newAuth.push({'text':items.description,'value':items.tag,'category':items.category})
                        };
                    });
                    item.newAuthorizationList = newAuth;
                    authorList.push(item);
                }); 
                 deferred.resolve(authorList);
            });
  
        });
        return deferred.promise;
    }

}

angular.module("authorityService",[]).service("authorityService",['$http','$q','routeService',"authorizationService","authorizationTypeService",authorityService]);